package com.gupaoedu.starter.autoConfiguration;

import com.gupaoedu.starter.HelloFormatTemplate;
import com.gupaoedu.starter.format.FormatProcessor;
import com.gupaoedu.starter.format.JsonFormatProcessor;
import com.gupaoedu.starter.format.StringFormatProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class FormatAutoConfiguration {

    @ConditionalOnMissingClass("com.alibaba.fastjson.JSON")
    @Primary
    @Bean
    public StringFormatProcessor stringFormatProcessor(){
        return new StringFormatProcessor();
    }

    @ConditionalOnClass(name = "com.alibaba.fastjson.JSON")
    @Bean
    public JsonFormatProcessor jsonFormatProcessor(){
        return new JsonFormatProcessor();
    }

    @Bean
    public HelloFormatTemplate helloFormatTemplate(FormatProcessor formatProcessor){
        return new HelloFormatTemplate(formatProcessor);
    }

}
